// RegularPolygon.java
// by Alexandre Martins, 2013
// MAC 5857 - Prof. Leonidas

package example.ilm.model;

import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.lang.Math;

public class RegularPolygon extends Polygon {

    private String elementName;

    public RegularPolygon(int numberOfVertices) {
        this("regularPolygon", numberOfVertices);
    }

    public RegularPolygon(String elementName, int numberOfVertices) {
        super(elementName);
        this.elementName = elementName;

        final double r = 50.0;
        for(int i=0; i<numberOfVertices; i++) {
            double angle = (double)(i) * (2.0 * Math.PI) / (double)numberOfVertices;
            double x = r * Math.cos(angle);
            double y = r * Math.sin(angle);
            vertices.add(new Point2D.Double(x, -y));
        }
    }

    public String toString() {
        return "" + 
            "<" + elementName + ">" + 
                "<name>" + getName() + "</name>" + 
                "<description>" + getDescription() + "</description>" + 
                "<position>" +
                    positionToString() +
                "</position>" + 
                "<scale>" + scale + "</scale>" +
                "<angle>" + angle + "</angle>" +
                "<color>" +
                    colorToString() + 
                "</color>" +
                "<vertices>" +
                    verticesToString() +
                "</vertices>" +
            "</" + elementName + ">" +
        "";
    }
}
